ALMaSS  1.0
The Animal, Landscape and Man Simulation System
Calendar Class Reference

#include <calendar.h>

Public Member Functions

void Reset (void)
 
bool TickMinute (void)
 
bool TickMinute10 (void)
 
bool TickHour (void)
 
void Tick (void)
 
long Date (void)
 
int DayInYear (void)
 
long OldDays (void)
 
long GlobalDate (int a_day, int a_month, int a_year)
 
int DayLength (void)
 
int DayLength (int a_day_in_year)
 
int GetFirstYear (void)
 
int GetLastYear (void)
 
int GetYear (void)
 
int GetYearNumber (void)
 
int GetMonth (void)
 
int GetMinute (void)
 
int GetHour (void)
 
int GetDayInMonth (void)
 
double GetDaylightProportion (void)
 
bool JanFirst (void)
 
bool MarchFirst (void)
 
void SetFirstYear (int a_year)
 
void SetLastYear (int a_year)
 
bool ValidDate (int a_day, int a_month)
 
int DayInYear (int a_day, int a_month)
 
 Calendar (void)
 

Private Attributes

long m_date
 
long m_olddays
 
int m_firstyear
 
int m_lastyear
 
int m_day_in_month
 
int m_day_in_year
 
int m_month
 
int m_year
 
int m_simulationyear
 
int m_todayslength
 
double m_daylightproportion
 
int m_minutes
 
int m_hours
 
bool m_janfirst
 
bool m_marchfirst
 

Static Private Attributes

static int m_daylength []
 The length of the day between sun up and sun down im minutes (DK - Jutland) More...
 

Constructor & Destructor Documentation

◆ Calendar()

Calendar::Calendar ( void  )
56 {
57  Reset();
58 }
void Reset(void)
Definition: calendar.cpp:40

References Reset().

Member Function Documentation

◆ Date()

◆ DayInYear() [1/2]

int Calendar::DayInYear ( int  a_day,
int  a_month 
)
97 {
98  const int m_monthsum[12] = {
99  0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
100 
101  return m_monthsum[ a_month - 1 ] + a_day - 1;
102 }

◆ DayInYear() [2/2]

◆ DayLength() [1/2]

int Calendar::DayLength ( int  a_day_in_year)
68 {
69  if ( a_day_in_year<0 || a_day_in_year>364 ) {
70  g_msg->Warn( WARN_BUG, "Calendar::DayLength(): Day outside a year!",
71  "" );
72  exit(1);
73  }
74  return m_daylength[ a_day_in_year ];
75 }
static int m_daylength[]
The length of the day between sun up and sun down im minutes (DK - Jutland)
Definition: calendar.h:102
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41
@ WARN_BUG
Definition: maperrormsg.h:34

References g_msg, m_daylength, MapErrorMsg::Warn(), and WARN_BUG.

◆ DayLength() [2/2]

int Calendar::DayLength ( void  )
inline
63 { return m_todayslength; }
int m_todayslength
Definition: calendar.h:95

References m_todayslength.

Referenced by Landscape::SupplyDaylength().

◆ GetDayInMonth()

int Calendar::GetDayInMonth ( void  )
inline

◆ GetDaylightProportion()

double Calendar::GetDaylightProportion ( void  )
inline
73 { return m_daylightproportion; }
double m_daylightproportion
Definition: calendar.h:96

References m_daylightproportion.

Referenced by Landscape::SupplyDaylightProp(), and Landscape::SupplyNightProp().

◆ GetFirstYear()

int Calendar::GetFirstYear ( void  )
inline
65 { return m_firstyear; }
int m_firstyear
Definition: calendar.h:88

References m_firstyear.

◆ GetHour()

int Calendar::GetHour ( void  )
inline

◆ GetLastYear()

int Calendar::GetLastYear ( void  )
inline
66 { return m_lastyear; }
int m_lastyear
Definition: calendar.h:89

References m_lastyear.

Referenced by Weather::Weather().

◆ GetMinute()

int Calendar::GetMinute ( void  )
inline
70 { return m_minutes; }
int m_minutes
Definition: calendar.h:97

References m_minutes.

Referenced by Hunter_Population_Manager::RecordHuntingSuccess(), and Landscape::SupplyMinute().

◆ GetMonth()

int Calendar::GetMonth ( void  )
inline

◆ GetYear()

int Calendar::GetYear ( void  )
inline
67 { return m_year; }
int m_year
Definition: calendar.h:93

References m_year.

Referenced by PesticideMap::DumpPMap(), Landscape::SupplyYear(), and Landscape::VegDump().

◆ GetYearNumber()

◆ GlobalDate()

long Calendar::GlobalDate ( int  a_day,
int  a_month,
int  a_year 
)
62 {
63  return m_olddays + DayInYear( a_day, a_month) + a_year*365;
64 }
long m_olddays
Definition: calendar.h:87
int DayInYear(void)
Definition: calendar.h:58

References DayInYear(), and m_olddays.

◆ JanFirst()

bool Calendar::JanFirst ( void  )
inline

◆ MarchFirst()

bool Calendar::MarchFirst ( void  )
inline
75 { return m_marchfirst; }
bool m_marchfirst
Definition: calendar.h:100

References m_marchfirst.

Referenced by Landscape::Tick().

◆ OldDays()

long Calendar::OldDays ( void  )
inline

◆ Reset()

void Calendar::Reset ( void  )
41 {
42  m_date = 0;
43  m_olddays = 0;
44  m_day_in_month = 1;
45  m_minutes = 0;
46  m_hours = 0;
47  m_day_in_year = 0; // [0..364]
48  m_month = 0; // [0..11]
50  m_simulationyear = 0;
51  m_janfirst = true;
52  m_marchfirst = false;
53 }

References m_date, m_day_in_month, m_day_in_year, m_firstyear, m_hours, m_janfirst, m_marchfirst, m_minutes, m_month, m_olddays, m_simulationyear, and m_year.

Referenced by Calendar(), Landscape::Landscape(), and Weather::Weather().

◆ SetFirstYear()

void Calendar::SetFirstYear ( int  a_year)
inline
76 { m_firstyear = a_year; }

References m_firstyear.

Referenced by Weather::Weather().

◆ SetLastYear()

void Calendar::SetLastYear ( int  a_year)
inline
77 { m_lastyear = a_year; }

References m_lastyear.

Referenced by Weather::Weather().

◆ Tick()

void Calendar::Tick ( void  )
142 {
143  const int m_monthlength[12] = {
144  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
145  const int m_maxmonth = 11;
146 
147  m_minutes = 0;
148  m_hours = 0;
149  m_date++;
150  m_day_in_year++;
151  m_day_in_month++;
152  m_janfirst = false;
153  m_marchfirst = false;
154 
155  if ( m_day_in_month > m_monthlength[ m_month ])
156  {
157  m_day_in_month = 1;
158  m_month++;
159  if ( m_month == 2 )
160  // March 1st.
161  m_marchfirst = true;
162  }
163 
164  if ( m_month > m_maxmonth )
165  {
166  m_month = 0;
167  m_year++;
169  m_olddays += 365;
170  m_janfirst = true;
171  m_day_in_year = 0;
172  }
175 }

References m_date, m_day_in_month, m_day_in_year, m_daylength, m_daylightproportion, m_hours, m_janfirst, m_marchfirst, m_minutes, m_month, m_olddays, m_simulationyear, m_todayslength, and m_year.

Referenced by Landscape::Tick().

◆ TickHour()

bool Calendar::TickHour ( void  )
129 {
130  bool dotick = false;
131 
132  if ( ++m_hours > 23 ) {
133  m_minutes = 0;
134  m_hours = 0;
135  dotick = true;
136  }
137  return dotick;
138 }

References m_hours, and m_minutes.

Referenced by RunTheSim().

◆ TickMinute()

bool Calendar::TickMinute ( void  )
107 {
108  bool dotick = false;
109 
110  if (m_minutes++ > 59) {
111  m_minutes = 0;
112  dotick = true;
113  }
114  return dotick;
115 }

References m_minutes.

◆ TickMinute10()

bool Calendar::TickMinute10 ( void  )
118 {
119  bool dotick = false;
120  m_minutes += 10;
121  if (m_minutes > 59) {
122  m_minutes = 0;
123  dotick = true;
124  }
125  return dotick;
126 }

References m_minutes.

Referenced by RunTheSim().

◆ ValidDate()

bool Calendar::ValidDate ( int  a_day,
int  a_month 
)
80 {
81  const int m_monthlength[12] = {
82  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
83 
84  if ( a_month < 1 ||
85  a_month > 12 ||
86  a_day < 1 ||
87  a_day > m_monthlength[ a_month - 1 ] ) {
88  return false;
89  } else {
90  return true;
91  }
92 }

Member Data Documentation

◆ m_date

long Calendar::m_date
private

Referenced by Date(), Reset(), and Tick().

◆ m_day_in_month

int Calendar::m_day_in_month
private

Referenced by GetDayInMonth(), Reset(), and Tick().

◆ m_day_in_year

int Calendar::m_day_in_year
private

Referenced by DayInYear(), Reset(), and Tick().

◆ m_daylength

int Calendar::m_daylength
staticprivate

The length of the day between sun up and sun down im minutes (DK - Jutland)

Referenced by DayLength(), and Tick().

◆ m_daylightproportion

double Calendar::m_daylightproportion
private

Referenced by GetDaylightProportion(), and Tick().

◆ m_firstyear

int Calendar::m_firstyear
private

Referenced by GetFirstYear(), Reset(), and SetFirstYear().

◆ m_hours

int Calendar::m_hours
private

Referenced by GetHour(), Reset(), Tick(), and TickHour().

◆ m_janfirst

bool Calendar::m_janfirst
private

Referenced by JanFirst(), Reset(), and Tick().

◆ m_lastyear

int Calendar::m_lastyear
private

Referenced by GetLastYear(), and SetLastYear().

◆ m_marchfirst

bool Calendar::m_marchfirst
private

Referenced by MarchFirst(), Reset(), and Tick().

◆ m_minutes

int Calendar::m_minutes
private

◆ m_month

int Calendar::m_month
private

Referenced by GetMonth(), Reset(), and Tick().

◆ m_olddays

long Calendar::m_olddays
private

Referenced by GlobalDate(), OldDays(), Reset(), and Tick().

◆ m_simulationyear

int Calendar::m_simulationyear
private

Referenced by GetYearNumber(), Reset(), and Tick().

◆ m_todayslength

int Calendar::m_todayslength
private

Referenced by DayLength(), and Tick().

◆ m_year

int Calendar::m_year
private

Referenced by GetYear(), Reset(), and Tick().


The documentation for this class was generated from the following files: